using System;
using System.Text;

using System.Collections.Specialized;

namespace Antix.Mail
{
    /// <summary>
    /// Content for a mail message
    /// </summary>
    public class MessageContent
    {
        #region Constructors

        /// <summary>
        /// Create a new message Content, with blank headers
        /// </summary>
        public MessageContent()
        {
            _Headers = new MessageContentHeaders("");
            _DataRaw = null;
        }

        /// <summary>
        /// Create a new message Content
        /// </summary>
        /// <param name="headers">Content headers</param>
        /// <param name="dataRaw">Raw data</param>
        public MessageContent(MessageContentHeaders headers, string dataRaw)
        {
            _Headers = headers;
            this.DataRaw = dataRaw;
        }

        #endregion

        #region Properties

        #region Headers

        private MessageContentHeaders _Headers;

        /// <summary>
        /// Headers for this message Content
        /// </summary>
        protected internal MessageContentHeaders Headers
        {
            get { return _Headers; }
        }

        #endregion

        #region ContentType

        /// <summary>
        /// Content type e.g. text/plain, text/html etc.
        /// </summary>
        public string ContentType
        {
            get { return _Headers.ContentType; }
        }

        #endregion

        #region Disposition

        /// <summary>
        /// Content disposition
        /// </summary>
        public string Disposition
        {
            get { return _Headers.Disposition; }
        }

        #region FileName

        /// <summary>
        /// Present for attachments
        /// </summary>
        public string FileName
        {
            get { return _Headers.FileName; }
        }

        #endregion

        #endregion

        #region Encoding

        /// <summary>
        /// Used for html encoding
        /// </summary>
        public string Encoding
        {
            get { return _Headers.Encoding; }
        }

        #endregion

        #region Size

        private int _Size;

        /// <summary>
        /// Content Size
        /// </summary>
        public int Size
        {
            get { return _Size; }
            set { _Size = value; }
        }

        #endregion

        #region Data

        private string _DataRaw;
        private string _Data;

        /// <summary>
        /// Content Data
        /// </summary>
        protected internal string DataRaw
        {
            get { return _DataRaw; }
            set
            {
                _DataRaw = value;

                // decode raw Data
                switch (Encoding)
                {
                    case MessageContentEncodingType.Base64:
                        _Data = TextFunctions.FromBase64(_DataRaw);

                        break;
                    case MessageContentEncodingType.QuotedPrintable:
                        _Data = QuotedPrintable.Decode(_DataRaw);

                        break;
                    default:
                        _Data = _DataRaw;

                        break;
                }
            }
        }

        /// <summary>
        /// Content Data
        /// </summary>
        protected internal string Data
        {
            get { return _Data; }
            set
            {
                _Data = value;

                // encode raw Data
                switch (Encoding)
                {
                    case MessageContentEncodingType.QuotedPrintable:
                        _DataRaw = QuotedPrintable.Encode(_Data);

                        break;
                    default:
                        _DataRaw = _Data;

                        break;
                }
            }
        }

        #endregion

        #endregion

        #region Methods

        #endregion
    }
}